package com.sky.mapper;

import com.sky.entity.Employee;
import com.sky.dto.EmployeePageQueryDTO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select id, username, password, name, status from employee where username = #{username}")
    Employee getByUsername(String username);
    
    /**
     * 员工分页查询
     */
    Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
    
    /**
     * 插入员工数据
     */
    @Insert("insert into employee (username, name, password, role, status, create_time, update_time) " +
            "values (#{username}, #{name}, #{password}, #{role}, #{status}, #{createTime}, #{updateTime})")
    void insert(Employee employee);
    
    /**
     * 根据id删除员工
     */
    @Delete("delete from employee where id = #{id}")
    void deleteById(Long id);
    
    /**
     * 更新员工状态
     */
    @Update("<script>" +
            "update employee" +
            "<set>" +
            "<if test='name != null'>name = #{name},</if>" +
            "<if test='username != null'>username = #{username},</if>" +
            "<if test='role != null'>role = #{role},</if>" +
            "<if test='status != null'>status = #{status},</if>" +
            "update_time = #{updateTime}" +
            "</set>" +
            "where id = #{id}" +
            "</script>")
    int update(Employee employee);
}